home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 January / macformat46.iso / Shareware Plus / Developers / Library / AVF 1.1 Pack / AVF 1.1 pack ƒ folder / AVF 1.1 pack ƒ / AppleVdig ƒ / main.cp < prev   
Encoding:
Text File  |  1996-09-29  |  2.8 KB  |  108 lines

  1. // ---------------------------------------------------------------------------
  2. //        • AVF 1.1 - Asynchronous Video Framework
  3. //      • 
  4. //      • Philippe Lang, 1733 Treyvaux, SWITZERLAND
  5. //      • plang@com.mcnet.ch
  6. // ---------------------------------------------------------------------------
  7. //      This program demonstrates the uses of AVF with a Video Input capable Macintosh
  8.  
  9. #include "VideoSession.h"
  10. #include "OffscreenWorld.h"
  11. #include "OffscreenGroup.h"
  12. #include "AsyncBuffer.h"
  13.  
  14. enum mainErr { NewCWindowErr };
  15.  
  16. main()
  17. {
  18.     // initialisation
  19.     InitGraf( &qd.thePort );        
  20.     InitFonts();                    
  21.     FlushEvents( everyEvent, 0 );
  22.     InitWindows();
  23.     InitMenus();
  24.     TEInit();
  25.     InitDialogs( nil );
  26.     InitCursor();
  27.     
  28.     MoreMasters();
  29.     MoreMasters();
  30.     MaxApplZone();
  31.     MaxApplZone();
  32.     
  33.     // program starts here
  34.     try
  35.     {
  36.         VideoSession        theSession( AppleVdig );
  37.         Rect                theOffscreenRect = {0, 0, 120, 160};
  38.         OffscreenWorld        theImage0( 16, theOffscreenRect, nil );
  39.         OffscreenWorld        theImage1( 16, theOffscreenRect, nil );
  40.         OffscreenWorld        theImage2( 16, theOffscreenRect, nil );
  41.         OffscreenGroup        theImageGroup;
  42.         theImageGroup.AddOffWorldPtr( &theImage0 );
  43.         theImageGroup.AddOffWorldPtr( &theImage1 );
  44.         theImageGroup.AddOffWorldPtr( &theImage2 );
  45.         AsyncBuffer            theBuffer( &theSession, &theImageGroup );
  46.                                                     
  47.         WindowPtr            theWin;
  48.         Rect                theWinPos = {100, 100, 220, 260};
  49.         theWin = NewCWindow( nil, &theWinPos, "\pVdig", true, movableDBoxProc, (WindowPtr)-1, 0, 0 );
  50.         if ( theWin == nil ) throw NewCWindowErr;
  51.         SetPort( theWin );
  52.         
  53.         VDGrabOneFrameAsync( theSession.VdigComponent(), 0 );        // bug in Apple vdig, not necessary with the QuickCam
  54.         VDGrabOneFrameAsync( theSession.VdigComponent(), 1 );
  55.         do
  56.         {    
  57.             while ( !VDDone( theSession.VdigComponent(), 0 ) ) {};
  58.             VDGrabOneFrameAsync( theSession.VdigComponent(), 2 );
  59.             CopyBits( (BitMap*)*theImage2.PixMapH(), &theWin->portBits, &theOffscreenRect, &theOffscreenRect, srcCopy, nil );
  60.             
  61.             while ( !VDDone( theSession.VdigComponent(), 1 ) ) {};
  62.             VDGrabOneFrameAsync( theSession.VdigComponent(), 0 );
  63.             CopyBits( (BitMap*)*theImage0.PixMapH(), &theWin->portBits, &theOffscreenRect, &theOffscreenRect, srcCopy, nil );
  64.             
  65.             while ( !VDDone( theSession.VdigComponent(), 2 ) ) {};
  66.             VDGrabOneFrameAsync( theSession.VdigComponent(), 1 );
  67.             CopyBits( (BitMap*)*theImage1.PixMapH(), &theWin->portBits, &theOffscreenRect, &theOffscreenRect, srcCopy, nil );
  68.         }
  69.         while ( !Button() );
  70.         
  71.         DisposeWindow( theWin );
  72.     }
  73.     
  74.     // exception handlers
  75.     catch ( VideoErr    theErr )
  76.     {
  77.         SysBeep(0);
  78.         ExitToShell();
  79.     }
  80.     
  81.     catch ( OffscreenErr theErr )
  82.     {
  83.         SysBeep(0);
  84.         ExitToShell();
  85.     }
  86.     
  87.     catch ( AsyncBufferErr theErr )
  88.     {
  89.         SysBeep(0);
  90.         ExitToShell();
  91.     }
  92.     
  93.     catch ( mainErr theErr )
  94.     {
  95.         SysBeep(0);
  96.         ExitToShell();
  97.     }
  98.     
  99.     catch ( OffscreenGroupErr theErr )
  100.     {
  101.         SysBeep(0);
  102.         ExitToShell();
  103.     }
  104.     
  105.     // program is finished
  106.     return (1);
  107. };
  108.